package com.solomon.travel.common.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.solomon.travel.common.custom.mapper.ShopCustomMapper;
import com.solomon.travel.common.mapper.ProtocalMapper;
import com.solomon.travel.common.mapper.ShopMapper;
import com.solomon.travel.common.model.Page;
import com.solomon.travel.common.po.Protocal;
import com.solomon.travel.common.po.Shop;
import com.solomon.travel.common.po.ShopExample;
import com.solomon.travel.common.service.ShopService;

@Service
public class ShopServiceImpl implements ShopService {
	
	@Resource
	private ShopMapper shopMapper;
	
	@Resource
	private ProtocalMapper protocalMapper;

	@Override
	public int add(Shop shop) {
		return shopMapper.insertSelective(shop);
	}

	@Override
	public int update(Shop shop) {
		return shopMapper.updateByPrimaryKeySelective(shop);
	}

	@Override
	public int add(Protocal protocal) {
		return protocalMapper.insertSelective(protocal);
	}

	@Override
	public int update(Protocal protocal) {
		return protocalMapper.updateByPrimaryKeySelective(protocal);
	}

	@Override
	public Shop getbyUser(String objectId) {
		ShopExample example = new ShopExample();
		example.createCriteria().andUserIdEqualTo(objectId);
		List<Shop> shops = shopMapper.selectByExample(example);
		if (!shops.isEmpty()) {
			return shops.get(0);
		}
		return null;
	}

	@Override
	public int count() {
		return shopMapper.countByExample(null);
	}
	
	@Resource
	private ShopCustomMapper shopCustomMapper;

	@Override
	public List<Shop> listShop(Page page) {
		return shopCustomMapper.listByPage(page);
	}

	@Override
	public Integer countBySerch(Shop shop) {
		return shopCustomMapper.countBySerch(shop);
	}

	@Override
	public List<Shop> listBySerch(Shop shop, Page page) {
		return shopCustomMapper.listBySerch(shop, page);
	}

}
